// pages/malldetail/malldetail.js
const app = getApp()
Page({
  data: {
    scrollHeight:800,
    list:[],
    totalYunFeeList:[]
  },
  onLoad: function (options) {
    var name = options.name;
    var areaId = options.areaId;
    var headerHeight = 44;
    let calcHeight = ((headerHeight + app.globalData.systemInfo.statusBarHeight) * (750 / app.globalData.systemInfo.windowWidth));
    var scrollHeight  = app.globalData.windowHeight - calcHeight;
    this.setData({
      scrollHeight: scrollHeight
    })
    wx.setNavigationBarTitle({
      title: name 
    })
    app.request.postHeadForm('hgz/dict/queryDictAndSubById/4').then(res =>{
      this.setData({
          totalYunFeeList:res.data.children
      })
      this.getList(name,areaId);
    })
  },
  getList(name,areaId){
    var  params = {
      pageNum:1,
      pageSize:1000,
      brand:name,
      areaId:areaId
    }
    var that = this;
    app.request.postHeadForm('hgz/product/queryListWithPage', params).then(res => {
      var dataList = res.data.list;
      var totalYunFeeList = this.data.totalYunFeeList;
      for (var i = 0; i < dataList.length;i++){
        for(var j=0;j<totalYunFeeList.length;j++){
          if(dataList[i].brand == totalYunFeeList[j].dictValue){
            for(var k=0;k<totalYunFeeList[j].children.length;k++){
              if(dataList[i].areaName == totalYunFeeList[j].children[k].dictName){
                dataList[i].price = dataList[i].price + Number(totalYunFeeList[j].children[k].dictValue);
                break;
              }
            }
            break;
          }
        }
        dataList[i].updateTm = dataList[i].updateTime.substring(5,16);
      }
      that.setData({
        list:dataList
      })
    })
  }

})